package com.hyt.it.ogt.kq.main.controller.bm;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.kq.common.bm.utils.Constant;
import com.hyt.it.ogt.kq.common.utils.KqStringUtils;
import com.hyt.it.ogt.kq.service.bm.model.entity.InvoiceItem;
import com.hyt.it.ogt.kq.service.bm.service.IInvoiceItemService;
import com.hyt.log.annotation.Log;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;

/**
 * <p>
 * 发票项目行明细 前端控制器
 * </p>
 *
 * @author liteng
 * @since 2020-09-01
 */
@Api(tags = "4.发票信息", value = "发票信息")
@ApiSort(value = 4)
@RestController
@RequestMapping("/bm/invoice-item")
public class InvoiceItemController {

    @Autowired
    IInvoiceItemService iInvoiceItemService;

    @ApiOperation(value = "4.1.1 保存发票信息", notes = "20000: 成功；31041101：保存发票数据失败")
    @ApiOperationSort(value = 1)
    @Log(module = "发票信息管理", business = "保存发票信息")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody InvoiceItem invoiceItem) {
        boolean bool = true;
        if (KqStringUtils.isBlank(invoiceItem.getId())) {
            bool  =  iInvoiceItemService.save(invoiceItem);
        } else {
            bool  =  iInvoiceItemService.saveOrUpdate(invoiceItem);
        }
		if (bool) {
			return ApiResponse.builder().code(20000).data(invoiceItem).build();
		} else {
			return ApiResponse.builder().code(31041101).data(invoiceItem).build();
		}
    }

    @ApiOperation(value = "4.1.2 查看发票信息", notes = "20000:成功；31041201：未查找到发票数据")
    @ApiOperationSort(value = 2)
    @RequestMapping(value = "/query/{id}", method = RequestMethod.GET)
    public Object query(@PathVariable String id) {
        InvoiceItem invoiceItem = iInvoiceItemService.getById(id);
        if (invoiceItem != null) {
			return ApiResponse.builder().code(20000).data(invoiceItem).build();
        } else {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_31010117).data(invoiceItem).build();
        }
    }
}
